var t = getApp();

Page({
    data: {
        scrollTop: 0,
        selected: 0,
        isLoadMore: !0,
        orderType: "community_buying",
        detailUrl: "orderdetail",
        total_page: 0,
        page: 1,
        action: "",
        orderList: [],
        waitPayList: [],
        waitSendList: [],
        waitReceiveList: [],
        waitCompleteList: [],
        stopRefresh: !1,
        order_ids: [],
        isMultiplePay: !1,
        buyingid: 0,
        keywords: ""
    },
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            keywords: a
        });
    },
    inpbtnclear: function() {
        this.setData({
            keywords: ""
        });
    },
    search: function() {
        this._getOrderList(this.data.selected);
    },
    onLoad: function(t) {
        t.status && this.setData({
            selected: t.status
        }), t.buyingid && this.setData({
            buyingid: t.buyingid
        });
    },
    onReady: function() {},
    onShow: function() {
        this._getOrderList(this.data.selected);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.stopRefresh ? wx.stopPullDownRefresh() : (this._initData(), this._getOrderList(this.data.selected));
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData(this.data.page, this.data.selected) : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    _initData: function() {
        this.setData({
            isLoadMore: !0
        }), this.data.page = 1, this.data.total_page = 0;
    },
    _getOrderList: function(t) {
        0 == t ? this.data.action = "plugin.package-deliver.frontend.order.list.index" : 1 == t ? this.data.action = "plugin.package-deliver.frontend.order.list.waitPay" : 2 == t ? this.data.action = "plugin.package-deliver.frontend.order.list.waitDeliver" : 3 == t ? this.data.action = "plugin.package-deliver.frontend.order.list.completed" : 4 == t && (this.data.action = "plugin.package-deliver.frontend.order.list.cancelled"), 
        this._getNetData(this.data.action, t);
    },
    _getNetData: function(a, e) {
        var i = this;
        this.data.page = 1;
        var s = t.getNetAddresss(a);
        s += "&page=1", this.data.buyingid && 0 != this.data.buyingid && (s += "&group_id=" + this.data.buyingid), 
        t._getNetWork({
            url: s,
            data: {
                keyword: this.data.keywords
            },
            success: function(t) {
                var a = t.data;
                if (console.log(e, "测试"), 1 == a.result) {
                    var s = a.data;
                    i.data.total_page = s.total, 0 == e ? i.setData({
                        orderList: s.data
                    }) : 1 == e ? i.setData({
                        waitPayList: s.data
                    }) : 2 == e ? i.setData({
                        waitSendList: s.data
                    }) : 3 == e ? i.setData({
                        waitReceiveList: s.data
                    }) : 4 == e ? i.setData({
                        waitCompleteList: i.data.waitCompleteList.concat(s.data)
                    }) : i.setData({
                        waitRefund: s.data
                    });
                }
                wx.stopPullDownRefresh();
            },
            fail: function(t) {
                wx.stopPullDownRefresh(), console.log(t);
            }
        });
    },
    _getMoreData: function(a, e) {
        var i = this;
        if (!(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var s = t.getNetAddresss(this.data.action);
            s += "&page=" + this.data.page, this.data.buyingid && 0 != this.data.buyingid && (s += "&group_id=" + this.data.buyingid), 
            t._getNetWork({
                url: s,
                data: {
                    keyword: this.data.keywords
                },
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        var s = a.data;
                        0 == e ? i.setData({
                            orderList: i.data.orderList.concat(s.data)
                        }) : 1 == e ? i.setData({
                            waitPayList: i.data.waitPayList.concat(s.data)
                        }) : 2 == e ? i.setData({
                            waitSendList: i.data.waitSendList.concat(s.data)
                        }) : 3 == e ? i.setData({
                            waitReceiveList: i.data.waitReceiveList.concat(s.data)
                        }) : 4 == e ? i.setData({
                            waitCompleteList: i.data.waitCompleteList.concat(s.data)
                        }) : i.setData({
                            waitRefund: i.waitRefund.concat(s.data)
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    swichTabTItem: function(t) {
        var a = t.detail.index;
        this.setData({
            selected: a
        }), this._initData(), this._getOrderList(this.data.selected);
    },
    onPageScroll: function(t) {
        this.setData({
            scrollTop: t.scrollTop
        });
    },
    stopRefresh: function(t) {
        var a = t.detail;
        this.setData({
            stopRefresh: a
        });
    },
    multiplePayAction: function(t) {
        var a = t.detail;
        this.setData({
            order_ids: a
        }), a.length > 0 ? this.setData({
            isMultiplePay: !0
        }) : this.setData({
            isMultiplePay: !1
        });
    },
    gotoPickUpCard: function() {
        wx.navigateTo({
            url: "/packageE/pickUpCard/pickUpCardIndex/pickUpCardIndex"
        });
    },
    toMultiplePay: function() {
        wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + this.data.order_ids.join(",") + "&status=2"
        });
    },
    cofirmOrderAction: function(t) {
        var a = t.detail;
        if (0 == this.data.selected) this._getOrderList(this.data.selected); else if ("pay" == a) this._getOrderList(this.data.selected); else {
            for (var e = this.data.waitReceiveList, i = 0; i < e.length; i++) a == e[i].id && e.splice(i, 1);
            this.setData({
                waitReceiveList: e
            });
        }
    }
});